﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Diagnostics;

namespace Game1_Resist50
{
    class Monster : GameObject
    {
        public Monster()
        {
            while (ObjectRectangle().IntersectsWith(Player.Instance().ObjectRectangle()))
            {
                _position.X = _rand.Next(0, GraphicsHelper.BmpWidth);
                _position.Y = _rand.Next(0, GraphicsHelper.BmpHeight);
            }
        }

        static private Bitmap _monsterImage = new Bitmap(Bitmap.FromFile(@".\Img\monster.png"), 5, 5);
        public override Bitmap ObjectImage()
        {
            return _monsterImage;
        }
        public override int ObjectWidth()
        {
            return _monsterImage.Width;
        }
        public override int ObjectHeight()
        {
            return _monsterImage.Height;
        }
        private int GetCloseToPoint(int origin, int point)
        {
            int offset = _rand.Next(1, _maxOffset);
            return point > origin ? origin + offset : origin - offset;
        }
        public override void UpdatePosition()
        {
            // // position move default offset.
            //int offset = _rand.Next(-1 * _maxOffset, MaxOffset);
            //_position.X = (_position.X + offset) % GraphicsHelper.BmpWidth;
            //if (_position.X < 0)
            //{
            //    _position.X += GraphicsHelper.BmpWidth;
            //}

            //offset = _rand.Next(-1 * _maxOffset, _maxOffset);
            //_position.Y = (_position.Y + offset) % GraphicsHelper.BmpHeight;
            //if (_position.Y < 0)
            //{
            //    _position.Y += GraphicsHelper.BmpHeight;
            //}
            
            // Get close to the cursor
            var player = Player.Instance();

            _position.X = GetCloseToPoint(_position.X, player.X) % GraphicsHelper.BmpWidth;
            if (_position.X < 0)
            {
                _position.X += GraphicsHelper.BmpWidth;
            }
            _position.Y = GetCloseToPoint(_position.Y, player.Y) % GraphicsHelper.BmpHeight;
            if (_position.Y < 0)
            {
                _position.Y += GraphicsHelper.BmpHeight;
            }
        }
        public override Rectangle ObjectRectangle()
        {
            return new Rectangle(_position.X, _position.Y, _monsterImage.Width, _monsterImage.Height);
        }
    }
}
